const findTreePathFlat = (treeData, key, config = {}) => {
  const { id = 'id' } = config;

  const find = (data, key, path = []) => {
    for (let i = 0; i < data.length; i++) {
      const item = data[i];
      path.push(item);
      if (item[id] === key || (item.children && find(item.children, key, path))) {
        return path;
      }
      path.pop();
    }
    return null;
  };

  return find(treeData, key);
};

export default findTreePathFlat;
